package com.huawei.tree.huffman_tree;

//节点
public class Node implements  Comparable<Node>{
    //节点权值
    int value;
    //指向左节点
    Node left;
    //指向右节点
    Node right;

    public Node(int value) {
        this.value = value;
    }

    //前序遍历1
    public void preOrder1() {
        if (this.left ==null && this.right == null) {
            System.out.print(value + "、");
        }
        if (this.left != null) {
            this.left.preOrder1();
        }
        if (this.right != null) {
            this.right.preOrder1();
        }
    }

    //前序遍历2
    public void preOrder2() {
        if (this.left ==null && this.right == null) {
            System.out.print(value + "、");
        }
        if (this.left != null) {
            this.left.preOrder2();
        }
        if (this.right != null) {
            this.right.preOrder2();
        }
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public Node getLeft() {
        return left;
    }

    public void setLeft(Node left) {
        this.left = left;
    }

    public Node getRight() {
        return right;
    }

    public void setRight(Node right) {
        this.right = right;
    }

    @Override
    public String toString() {
        return "Node{" +
                "value=" + value +
                '}';
    }

    @Override
    public int compareTo(Node o) {
        return this.value - o.value;
    }
}
